package day_2022_9_to_12.Day;

import java.util.Arrays;
import java.util.PriorityQueue;

/**
 * @author haomin
 * @date 2022/09/11 10:29
 **/
public class Day9_4_Num6178_MinGroups {
    class Solution {
        public int minGroups(int[][] intervals) {
            Arrays.sort(intervals,(a, b) -> a[0]==b[0]?a[1]-b[1]:a[0]-b[0]);
            PriorityQueue<Integer> q = new PriorityQueue<>();
            for(int[] arr : intervals){
                if(!q.isEmpty() && arr[0] > q.peek()){
                    q.poll();
                }
                q.offer(arr[1]);
            }
            return q.size();
        }
    }
}